<template>
  <p-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-form-item label="年" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'year', validatorRules.year]" placeholder="请输入年"></p-input>
        </p-form-item>
        <p-form-item label="月" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'month', validatorRules.month]" placeholder="请输入月"></p-input>
        </p-form-item>
        <p-form-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-depart v-decorator="['dptname', validatorRules.dptname]" :trigger-change="true"/>
        </p-form-item>
        <p-form-item label="车间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'workroomname', validatorRules.workroomname]" placeholder="请输入车间"></p-input>
        </p-form-item>
        <p-form-item label="车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'workroomno', validatorRules.workroomno]" placeholder="请输入车间编码"></p-input>
        </p-form-item>
        <p-form-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <f-popup
            contextPath="basic-business"
            v-decorator="['classname', validatorRules.classname]"
            :trigger-change="true"
            org-fields="id,classno,classname"
            dest-fields="classid,classno,classname"
            code="mes_hr_q_classinfo"
            @callback="popupCallback"/>
        </p-form-item>
        <p-form-item label="工号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <f-popup
            contextPath="mes-manpower"
            v-decorator="['empno', validatorRules.empno]"
            :trigger-change="true"
            org-fields="empno,empname,id"
            dest-fields="empno,empname,id"
            code="mes_hr_employeeinfo"
            @callback="popupCallback"/>
        </p-form-item>
        <p-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'empname', validatorRules.empname]" placeholder="请输入姓名"></p-input>
        </p-form-item>
        <p-form-item label="质量禁令问题次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'qualityLockqQty', validatorRules.qualityLockqQty]" placeholder="请输入质量禁令问题次数" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="批量问题次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'batchqQty', validatorRules.batchqQty]" placeholder="请输入批量问题次数" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="客诉问题次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'cssqQty', validatorRules.cssqQty]" placeholder="请输入客诉问题次数" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="禁令考核参考档位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'lockAssessLevel', validatorRules.lockAssessLevel]" placeholder="请输入禁令考核参考档位"></p-input>
        </p-form-item>
        <p-form-item label="绩效" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'performance', validatorRules.performance]" placeholder="请输入绩效"></p-input>
        </p-form-item>
        <p-form-item label="当前审批人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'currentApprover', validatorRules.currentApprover]" placeholder="请输入当前审批人"></p-input>
        </p-form-item>
        <p-form-item label="审批记录" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'approveRecord', validatorRules.approveRecord]" placeholder="请输入审批记录"></p-input>
        </p-form-item>
        <p-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入状态"></p-input>
        </p-form-item>
        <p-form-item label="作业质量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'workQuality', validatorRules.workQuality]" placeholder="请输入作业质量"></p-input>
        </p-form-item>
        <p-form-item label="作业效率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'workEffi', validatorRules.workEffi]" placeholder="请输入作业效率"></p-input>
        </p-form-item>
        <p-form-item label="现场管理" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'fieldManage', validatorRules.fieldManage]" placeholder="请输入现场管理"></p-input>
        </p-form-item>
        <p-form-item label="综合评价" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'comAssessment', validatorRules.comAssessment]" placeholder="请输入综合评价"></p-input>
        </p-form-item>
        <p-form-item label="月度考核得分" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'monAssessSorce', validatorRules.monAssessSorce]" placeholder="请输入月度考核得分"></p-input>
        </p-form-item>
        <p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
        </p-form-item>

      </p-form>
    </p-spin>
    <p-button type="primary" @click="handleOk">确定</p-button>
    <p-button type="primary" @click="handleCancel">取消</p-button>
  </p-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  
  export default {
    name: "MesHrMonthlyPaResultModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JSelectDepart,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          year: {rules: [
            {required: true, message: '请输入年!'},
          ]},
          month: {rules: [
            {required: true, message: '请输入月!'},
          ]},
          dptname: {rules: [
            {required: true, message: '请输入部门!'},
          ]},
          workroomname: {rules: [
            {required: true, message: '请输入车间!'},
          ]},
          workroomno: {rules: [
          ]},
          classname: {rules: [
            {required: true, message: '请输入班组!'},
          ]},
          empno: {rules: [
            {required: true, message: '请输入工号!'},
          ]},
          empname: {rules: [
          ]},
          qualityLockqQty: {rules: [
            {required: true, message: '请输入质量禁令问题次数!'},
            {pattern:/^-?\d+$/, message: '请输入整数!'},
          ]},
          batchqQty: {rules: [
            {required: true, message: '请输入批量问题次数!'},
            {pattern:/^-?\d+$/, message: '请输入整数!'},
          ]},
          cssqQty: {rules: [
            {required: true, message: '请输入客诉问题次数!'},
            {pattern:/^-?\d+$/, message: '请输入整数!'},
          ]},
          lockAssessLevel: {rules: [
            {required: true, message: '请输入禁令考核参考档位!'},
          ]},
          performance: {rules: [
            {required: true, message: '请输入绩效!'},
          ]},
          currentApprover: {rules: [
          ]},
          approveRecord: {rules: [
          ]},
          status: {rules: [
          ]},
          workQuality: {rules: [
            {required: true, message: '请输入作业质量!'},
          ]},
          workEffi: {rules: [
            {required: true, message: '请输入作业效率!'},
          ]},
          fieldManage: {rules: [
            {required: true, message: '请输入现场管理!'},
          ]},
          comAssessment: {rules: [
            {required: true, message: '请输入综合评价!'},
          ]},
          monAssessSorce: {rules: [
            {required: true, message: '请输入月度考核得分!'},
          ]},
          remark: {rules: [
            {required: true, message: '请输入备注!'},
          ]},
        },
        url: {
          add: '/mes-manpower/auto/mesHrMonthlyPaResult/add',
          edit: '/mes-manpower/auto/mesHrMonthlyPaResult/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'year','month','dptname','workroomname','workroomno','classname','empno','empname','qualityLockqQty','batchqQty','cssqQty','lockAssessLevel','performance','currentApprover','approveRecord','status','workQuality','workEffi','fieldManage','comAssessment','monAssessSorce','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              let formData = Object.assign(this.model, values);
              this.formData = Object.assign(this.model, values);
              //新增触发
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
                if(this.EnhanceJS.afterAdd){
                  //新增之前
                  let Obj = eval(this.EnhanceJS.afterAdd)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }else{
                //编辑触发
                httpurl+=this.url.edit;
                method = 'put';
                if(this.EnhanceJS.afterEdit){
                 //编辑之前
                  let Obj = eval(this.EnhanceJS.afterEdit)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'year','month','dptname','workroomname','workroomno','classname','empno','empname','qualityLockqQty','batchqQty','cssqQty','lockAssessLevel','performance','currentApprover','approveRecord','status','workQuality','workEffi','fieldManage','comAssessment','monAssessSorce','createBy','createTime','updateBy','updateTime','remark'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>